//
//  CLHSwiftCodeVC.swift
//  ListViewModel_Example
//
//  Created by 曹连华 on 2019/11/28.
//  Copyright © 2019 clh2046@163.com. All rights reserved.
//

import UIKit

class CLHSwiftCodeVC: UIViewController {
    
    lazy var viewModel:CLHSwiftCodeViewModel = {
        let vm = CLHSwiftCodeViewModel()
        return vm
    }()
    
    lazy var mainTableView: UITableView = {
       let tabliView = UITableView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height), style: .plain)
        tabliView.delegate = self;
        tabliView.dataSource = self.viewModel.dataSource
        tabliView.estimatedRowHeight = 120;
        tabliView.backgroundColor = UIColor.white
        tabliView.rowHeight = UITableViewAutomaticDimension
        tabliView.register(CLHSwiftCodeTVCell.self, forCellReuseIdentifier: "CLHSwiftCodeTVCell")
        return tabliView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.title = "SwiftCode"
        initUI()
    }
    private func initUI() {
        view.addSubview(mainTableView)
        mainTableView.reloadData()
    }

}

extension CLHSwiftCodeVC: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        viewModel.didSelectedRowModel(with: indexPath)
    }
    
}
class CLHSwiftCodeViewModel: LVBaseViewModel {
    
    lazy var dataSource:LVTableViewDataSource = {
        let ds = LVTableViewDataSource()
        return ds
    }()

    override func resetDataSource() {
        dataSource.resetRowList(inSection: rows())
    }
    
    private func rows() -> [LVBaseCellRowModel] {
        var rowArray: [LVBaseCellRowModel] = []
        for index in 1...10 {
            guard let rowModel = LVBaseCellRowModel(cellClass: "CLHSwiftCodeTVCell") else { continue }
            rowModel.mainTitle = "这是第\(index)行"
            rowModel.subTitle = "子标题\(index)"
            rowArray.append(rowModel)
        }
        
        return rowArray
    }
    
    override func didSelectedRowModel(with indexPath: IndexPath) {
        
    }
}
